package com.hai.books.controller;


import com.hai.books.entity.BookInfo;
import com.hai.books.service.BookInfoService;
import com.hai.response.Result;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(value = "书籍管理", tags="书籍")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class BookInfoController {

    @Autowired
    BookInfoService bookInfoService;

    @GetMapping("getBookInfoList")
    @ApiOperation(value = "查询图书集合" , notes = "xxxxx")
    public Result getBookInfoList(Integer type , String bookName , Integer isBorrowed ,
                                  @RequestParam(required = true , defaultValue = "1") Integer index ,
                                  @RequestParam(required = true , defaultValue = "5") Integer size){
        Map<String, Object> map = new HashMap<>();
        map.put("type",type);
        map.put("bookName",bookName);
        map.put("isBorrowed",isBorrowed);
        map.put("index",(index-1)*size);
        map.put("size",size);
        System.out.println(isBorrowed);
        int count = bookInfoService.queryBookIfoCount(map);
        List<BookInfo> bookInfoList = bookInfoService.queryBookInfoList(map);

        Map<String, Object> outMap = new HashMap<>();
        outMap.put("list",bookInfoList);
        outMap.put("count",count);
        return Result.ok().data("result",outMap);
    }



    @PutMapping ("updateBook")
    public Result updateBook(Integer bookid){
        int i = bookInfoService.updateBook(bookid);
        return Result.ok().data("result","true");
    }



}
